using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using QLNhaSach.BUS.DTO;

namespace QLNhaSach.DAO
{
    public  class DSSachNhapDAO
    {
        //Hien thi danh sach sach can nhap
        public static DataTable DSSN()
        {
            string sql = "SELECT * FROM DSSachNhap";
            return Config.AccessHelper.ExecuteQuery(sql);
        }

        //Them sach vao danh sach sach can nhap
        public static bool ThemSach(DSSachNhapDTO p)
        {
            try
            {
                string sql = "INSERT INTO DSSachNhap(MaSach,TenSach,TacGia,TheLoai,NXB,SoLuong)VALUES('" + p.MaSach + "','"+
                               p.TenSach +"','"+p.TacGia +"','"+p.TheLoai +"','"+p.NXB +"','"+p.SoLuong +"')";
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        //Cap nhat thong tin sach trong danh sach sach nhap
        public static bool CapNhatSach(DSSachNhapDTO p)
        {
            try
            {
                string sql = "UPDATE DSSachNhap SET  MaSach='" + p.MaSach + "',TenSach='" + p.TenSach + "',TacGia='" +
                            p.TacGia + "',TheLoai='" + p.TheLoai + "',NXB='" + p.NXB + "',SoLuong='" + p.SoLuong + "'where id=" + p.id;
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;

            }
        }

        //Xoa sach khoi danh sach sach nhap
        public static bool XoaSach(DSSachNhapDTO p)
        {
            try
            {
                string sql = "DELETE FROM DSSachNhap where id=" + p.id;
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
